package com;

import java.io.IOException;

import com.trusfort.service.ScanJunkDataService;

public class ScanJunkDataAndClear {

	
	public static String[] redisKeys = { 
			"XDID::aimei", 
			"XDID::abmac", 
			"XDID::amac", 
			"XDID::aaid", 
			"XDID::abid", 
			"XDID::absn",
			"XDID::afpid",
			"XDID::afdid", 
			"XDID::asn", 
			"XDID::acid",
			"XDID::afit",
			"XDID::afdidrand"
			};
	
	public static void main(String[] args) {
		
		if(args.length<1) {
			 System.out.println("请输入保存路径");
			 return;
		 }
		 
		 if(args.length<2) {
			 System.out.println("请输入输入待扫描Redis服务的Ip和端口，格式为ip:port 多个以逗号分隔");
			 return;
		 }
		 
		 
		 if(args.length<3) {
			 System.out.println("请输入要扫描数据条数阈值 ");
			 return;
		 }
		 
		 String savePath = args[0]; //"D:/test/redis_scan"
		 
		 String host = args[1];  //ip:port,ip:port,ip:port   //单机模式只有一个，集群模式多个， 哨兵模式使用单机模式
		 
		 String  limit = args[2];   //"10"
		
		 boolean clear = true;
		 
		 String redisKeyPrefix = "all";
		 if(args.length>=4) {
			 boolean redisKeyPrefixCorrect = false;
			 for(String redisKey:redisKeys) {
				 if(redisKey.contains(args[3])) {
					 redisKeyPrefixCorrect = true;
					 break;
				 }
			 }
			 
			 if(redisKeyPrefixCorrect) {
				 redisKeyPrefix = args[3];
			 }
			 
		 }
		 
		 String passwd=null;
		 if(args.length>=5 && !"null".equals(args[4])) {
			 passwd = args[4];
		 }
		 
		 
		 System.out.println("即将对Redis数据进行扫描分析，扫描出异常数据将自动删除，请确认是否继续进行，继续请输入【y】,取消请输入【n】 !!!!");
		 
		 try {
			 char read = (char)System.in.read();
			 if(read=='n') {
				 return ;
			 }
		} catch (IOException e) {
			e.printStackTrace();
		}
		 
		 ScanJunkDataService.statInvalidField(savePath,host,limit,clear,redisKeyPrefix,passwd);
		
	}

}
